//
//  UIButton+Extension.swift
//  sinaWB
//
//  Created by 杨运旺 on 15/11/8.
//  Copyright © 2015年 杨运旺. All rights reserved.
//

import UIKit


extension UIButton{
    
    
        /// `便利`构造函数
    convenience init(imgName:String,backImgName:String){
        self.init()
        
        setImage(UIImage(named:imgName), forState: UIControlState.Normal)
        setImage(UIImage(named: imgName + "_highlighted"), forState: UIControlState.Highlighted)
        setBackgroundImage(UIImage(named: backImgName), forState: UIControlState.Normal)
        setBackgroundImage(UIImage(named: backImgName + "_highlighted"), forState: UIControlState.Highlighted)
        
        
        //根据背景图片的大小调整按钮尺寸
        sizeToFit()
    }
    
    /// 便利构造函数
    ///
    /// - parameter title: title
    /// - parameter color: color
    /// - parameter image: 背景图像
    ///
    /// - returns: UIButton
    convenience init(title:String,color:UIColor,backImage:String){
        self.init()
        setTitle(title, forState: UIControlState.Normal)
        setTitleColor(color, forState: UIControlState.Normal)
        setBackgroundImage(UIImage(named: backImage), forState: UIControlState.Normal)
        sizeToFit()
    }
    
    /// 便利构造函数
    ///
    /// - parameter title: title
    /// - parameter color: color
    /// - parameter fontSize: 字体大小
    /// - parameter image: 图像名称
    ///
    /// - returns: UIButton
    convenience init(title:String,color:UIColor,image:String,fontSize:CGFloat){
        self.init()
        setTitle(title, forState: .Normal)
        setTitleColor(color, forState: .Normal)
        setImage(UIImage(named: image), forState: .Normal)
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        sizeToFit()
    }
}